/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.DomainLayer;

/**
 *
 * @author meydlo
 */
import java.util.ArrayList;
public class RentRecords{

    private static RentRecords rentRecords;
    private ArrayList<RentProduct> rentProductList;

    //
    private RentRecords(){
        rentProductList = new ArrayList<RentProduct>();
    }

    //
    public static RentRecords getRentRecords(){
        if(rentRecords==null)
        {
            rentRecords=new RentRecords();
        }
        return rentRecords;
    }

    //
    public RentProduct createRentProduct(long productId, String name, String description, int noOfOneType, double price, double discount)
    {

        RentProduct rentProduct=new RentProduct();

        rentProduct.setDescription(description);
        rentProduct.setId(productId);
        rentProduct.setName(name);
        rentProduct.setNoOfOneType(noOfOneType);
        rentProduct.setPrice(price);
        rentProduct.setDiscount(discount);

        addRentProduct(rentProduct);
        return rentProduct;

    }

    //
    public void addRentProduct(RentProduct rentProduct)
    {
        rentProductList.add(rentProduct);
    }

    //
    public RentProduct rentProductByID(long id)
    {
        for(int i=0; i<rentProductList.size();i++){
            if(rentProductList.get(i).getId()==id)
            {
                return rentProductList.get(i);
            }
        }
        return null;
    }

    //search for rentProduct
    public RentProduct rentProductByName(String name)
    {
        for(int i=0; i<rentProductList.size();i++){
            if(rentProductList.get(i).getName().equals(name)){
                return rentProductList.get(i);
            }
        }

        System.out.println("RentProduct wasn't found");
        return null;
    }


    //
    public void deleteRentProduct(long id)
    {
        if(rentProductByID(id)!=null){
            rentProductList.remove(rentProductByID(id));
            System.out.println("product successfully removed");
        }
    }

    //
    public ArrayList<RentProduct> getRentProductList()
    {
        return rentProductList;
    }

    public void setRentProductList(ArrayList<RentProduct> list)
    {
        this.rentProductList = list;
    }


    public void printRentProductList()
    {
        for(RentProduct rentProduct : rentProductList){
            System.out.println("id: "+rentProduct.getId()+" | name: "+rentProduct.getName()+" | in stok:"+rentProduct.getNoOfOneType());
        }
    }

    //testing purpose
    public int getNoOfRentProducts()
    {
        int noOfRentProducts=rentProductList.size();
        return noOfRentProducts;
    }

}
